package com.guanjialhx.pojo;

/**
 *  
 *   All rights Reserved, Designed By www.changhubao.com
 *   @projectName chb
 *   @title     Result   
 *   @package    com.changhubao.chb.utils  
 *   @description      
 *   @author 李相    
 *   @date   2019/6/20 17:16  
 *   @version V1.0.0
 *   @copyright 2019 www.changhubao.com
 *   注意 本内容仅限于长护宝科技有限公司，禁止外泄以及用于其他的商业 
 *  
 */
public class Result<T> {
    private String message;
    private int retCode;
    private T data;
    private Result(T data) {
        this.retCode = 0;
        this.message = "成功";
        String s = "";
        if (data !=null && !data.equals(s)){
            this.data = data;
        }
    }
    public Result(CodeMsg cm) {
        if(cm == null){
            return;
        }
        this.retCode = cm.getRetCode();
        this.message = cm.getMessage();
    }
    /**
     * 成功时候的调用
     * @return
     */
    public static <T> Result<T> success(T data){
        return new Result<T>(data);
    }
    /**
     * 成功，不需要传入参数
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> Result<T> success(){
        return (Result<T>) success("");
    }
    /**
     * 失败时候的调用
     * @return
     */
    public static <T> Result<T> error(String cm){
        return new Result<T>((T) cm);
    }
    /**
     * 失败时候的调用,扩展消息参数
     * @param cm
     * @param msg
     * @return
     */
    public static <T> Result<T> error(CodeMsg cm,String msg){
        cm.setMessage(cm.getMessage()+"--"+msg);
        return new Result<T>(cm);
    }
    public T getData() {
        return data;
    }
    public String getMessage() {
        return message;
    }
    public int getRetCode() {
        return retCode;
    }
}
